home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / RD_STK.ARJ / RD_DEMO.C next >
Text File  |  1992-03-01  |  6KB  |  184 lines

  1. /*-------------------------------------------------------------------
  2. |  This program demonstrates the functions in RD_STK   V1.1         |
  3. |                                                                   |
  4. |  (c) 1991 EC Systems, 2268 Glenmoor Rd S, Clearwater, Fl 34624    |
  5. --------------------------------------------------------------------*/
  6.  
  7. #include <graphics.h>
  8. #include <dos.h>
  9. #include <stdlib.h>
  10. #include <stdio.h>
  11. #include <conio.h>
  12. #include "rd_stk.h"
  13.  
  14. static    int    MaxX,MaxY,StartX,StartY;
  15. static    int x1,y1;
  16. static    int    ulx, uly, lrx, lry, size;
  17. static    *Saucer;
  18. static  int Maxcolor,saucercolor;
  19. static    int r = 20;
  20.  
  21. main()
  22. {
  23. int        stk1_x,stk1_y,stk2_x,stk2_y;
  24. int        stk1_b1,stk1_b2,stk2_b1,stk2_b2;
  25. int        ch,i;
  26. int     g_driver = DETECT;                        /* Request auto detection. */
  27. int        g_mode,g_error ;
  28.  
  29. void DrawBorder(void);
  30. void copyright(void);
  31. void Draw_Saucer(void);
  32. int     set_cursor(int);
  33.  
  34. /*---------------------------------------------------------------------
  35. |             Function call to RD_STK (To turn OFF Cursor)          |
  36. ----------------------------------------------------------------------*/
  37.     set_cursor(OFF);                              /* turns cursor off */
  38.  
  39.     window(1,1,80,25);
  40.     clrscr();
  41.     if ( registerbgidriver( EGAVGA_driver ) < 0)
  42.         exit(1);
  43.     if ( registerbgidriver( CGA_driver    ) < 0)
  44.         exit(1);
  45.     if ( registerbgidriver( Herc_driver   ) < 0)
  46.         exit(1);
  47.     initgraph( &g_driver, &g_mode, "" );        /* Initialize graphics */
  48.     g_error = graphresult();                    /* Read result of init */
  49.     if( g_error != grOk ){                        /* Error occured during init */
  50.         printf(" Graphics System Error: %s\n", grapherrormsg( g_error) );
  51.         exit( 1 );
  52.     }
  53.     MaxX = getmaxx();                            /* Read size of screen    X */
  54.     MaxY = getmaxy();                            /* Read size of screen    Y */
  55.     StartX = (.5 * MaxX);
  56.     StartY = (.5 * MaxY);
  57.     Maxcolor = getmaxcolor();
  58.     saucercolor = (Maxcolor);
  59.     DrawBorder();
  60.                                                 /* Plot some "stars"  */
  61.     for ( i=0 ; i<500; ++i ){
  62.         putpixel(random(MaxX), random(MaxY), random( Maxcolor-1 )+1);
  63.     }
  64.     copyright();
  65.     for(;;){
  66.         if(kbhit()) {                           /* check keyboard */
  67.             ch = getch();
  68.             if(ch == ESC) {                       /* is ESC key pressed */
  69.                 closegraph();
  70.                 textattr(WHITE + (BLACK<<4));
  71.                 set_cursor(ON_L);                /* sets cursor on with line */
  72.                 window(1,1,80,25);
  73.                 clrscr();
  74.                 free( Saucer );
  75.                 exit(0);                        /*  quit program  */
  76.             }
  77.         }
  78.  
  79. /*---------------------------------------------------------------------
  80. |             Function call to RD_STK (for buttons position)           |
  81. -----------------------------------------------------------------------*/
  82.         get_joybutton(&stk1_b1,&stk1_b2,&stk2_b1,&stk2_b2);
  83.  
  84.         if(stk1_b2){                            /* jystk1 button 2 pressed */
  85.             closegraph();
  86.             textattr(WHITE + (BLACK<<4));
  87.             set_cursor(ON_L);                    /* sets cursor on with line */
  88.             window(1,1,80,25);
  89.             clrscr();
  90.             free( Saucer );
  91.             exit(0);                            /*  quit program  */
  92.         }
  93.  
  94.         if(stk1_b1){                              /* jystk1 button 1 pressed */
  95.             if(saucercolor < Maxcolor){
  96.                 StartX = (x1 + 18);
  97.                 StartY = (y1 + 15);
  98.                 saucercolor++;
  99.                 delay(10);
  100.             }
  101.             if(saucercolor == Maxcolor){
  102.                 saucercolor = 1;
  103.             }
  104.             Draw_Saucer();
  105.         }
  106.  
  107. /*----------------------------------------------------------------------
  108. |          Function call to RD_STK (for X & Y Stick position)          |
  109. ----------------------------------------------------------------------*/
  110.         get_joypos(&stk1_x, &stk1_y, &stk2_x, &stk2_y );
  111.         x1 = stk1_x * 2;
  112.         y1 = stk1_y * 2;
  113.         if (x1 < 5 )                            /* checks x1 min */
  114.             x1 = 5  ;
  115.         if (x1 > MaxX-30 )                        /* checks x1 max */
  116.             x1 = MaxX-30;
  117.         if (y1 < 40 )                             /* checks y1 min */
  118.             y1 = 40    ;
  119.         if (y1 > MaxY-65)                        /* checks y1 max */
  120.             y1 = MaxY-65;
  121.         putimage(x1, y1, Saucer, XOR_PUT);        /*  draw image  */
  122.         delay(75);
  123.         putimage(x1, y1, Saucer, XOR_PUT);        /* erase image  */
  124.     }
  125.  
  126. }                                                /* end of program */
  127.  
  128. /* -------------------------------------------------------
  129. |        function call to draw border                |
  130. --------------------------------------------------------*/
  131. void DrawBorder()
  132. {
  133.  struct viewporttype vp;
  134.  
  135.     setviewport( 1, 2, MaxX, MaxY, 1 );         /* sets window size       */
  136.     setcolor( WHITE);                               /* Set color to white     */
  137.     setlinestyle( SOLID_LINE, 0, THICK_WIDTH );
  138.     getviewsettings( &vp );
  139.     rectangle( 0, 0, vp.right-vp.left, vp.bottom-vp.top );
  140. }
  141.  
  142. /* -------------------------------------------------------
  143. |        function call to draw copyright              |
  144. --------------------------------------------------------*/
  145. void copyright()
  146. {
  147.     rectangle(160,10,470,35);
  148.     setfillstyle(SOLID_FILL,CYAN);
  149.     floodfill(300,20,WHITE);
  150.     outtextxy(200,15,"(C)Copyright 1991 by EC Systems");
  151.     outtextxy(180,24,"  RD_STK  Joystick toolbox  V 1.1 ");
  152.  
  153.     rectangle(120,310,500,335);
  154.     setfillstyle(SOLID_FILL, CYAN);
  155.     floodfill(300,320,WHITE);
  156.     outtextxy(170,315,"Press Button 1 Start or change color");
  157.     outtextxy(180,324,"     Press Button 2 to Quit   ");
  158.  
  159. }
  160.  
  161. void Draw_Saucer()
  162. {                        /* Draw Saucer */
  163.  
  164.     setlinestyle( SOLID_LINE, 0, NORM_WIDTH );
  165.     setfillstyle( SOLID_FILL,saucercolor);
  166.     fillellipse(StartX, StartY, r, (r/3)+2);
  167.     ellipse(StartX, StartY-4, 190, 357, r, r/3);
  168.     line(StartX+7, StartY-6, StartX+10, StartY-12);
  169.     circle(StartX+10, StartY-12, 2);
  170.     line(StartX-7, StartY-6, StartX-10, StartY-12);
  171.     circle(StartX-10, StartY-12, 2);
  172.  
  173.                         /* Read saucer image */
  174.  
  175.     ulx = StartX-(r+1);
  176.     uly = StartY-14;
  177.     lrx = StartX+(r+1);
  178.     lry = StartY+(r/3)+3;
  179.     size = imagesize(ulx, uly, lrx, lry);
  180.     Saucer = malloc( size );
  181.      getimage(ulx, uly, lrx, lry, Saucer);
  182.     putimage(ulx, uly, Saucer, XOR_PUT);
  183.     delay(10);
  184. }